package tgl_services

import (
	"errors"
	tgl_models "xiehui-service/app/models/tgl"
	"xiehui-service/global"
)

type tjlbyclService struct {
}

var TjlbyclService = new(tjlbyclService)

// 新增
func (tjlbyclService *tjlbyclService) Create(jlbycl tgl_models.Tjlbycl) (int64, error) {
	result := global.App.TglDB.Create(&jlbycl)
	if result.Error != nil {
		return 0, result.Error
	}
	return jlbycl.FID, nil
}

func (tjlbyclService *tjlbyclService) GetOneInfo(FID int64) (tjlbyclInfo *tgl_models.Tjlbycl, err error) {
	err = global.App.TglDB.First(tjlbyclInfo, FID).Error
	if err != nil {
		err = errors.New("数据不存在")
		return nil, err
	}
	return tjlbyclInfo, nil
}

func (tjlbyclService *tjlbyclService) Update(tjlbycl tgl_models.Tjlbycl) (err error) {
	if err := global.App.TglDB.Model(&tgl_models.Tjlbycl{}).Where("FID = ?", tjlbycl.FID).Omit("FID", "FNo").Updates(&tjlbycl).Error; err != nil {
		return err
	}
	return nil
}
